<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>快捷动画</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
        .box{
            position: absolute;
            top: 50px;
            left: 50px;
            width: 150px;
            height: 150px;
            background-color: #f00;
        }

        .mask {
            position: fixed;
            top: 0;
            left: 0;
            display: none;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,.5);
        }

        .mask-content {
            width: 300px;
            height: 300px;
            margin: 50px auto;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <div class="box"></div>

    <button>消失</button>
    <button>出现</button>
    <button>出现/消失</button>
    <button>下拉出现</button>
    <button>上拉消失</button>
    <button>切换上拉/下拉</button>
    <button>渐隐</button>
    <button>渐现</button>
    <button>渐隐渐显</button>

    <button>出现遮罩</button>

    <div class="mask">
        <div class="mask-content"></div>
    </div>

    <script src="../lib/jquery/jquery.min.js"></script>
    <script type="text/javascript">
        var $box = $(".box");

        $box.click(function (){
            $(this).fadeTo(2000, .4);
        })

        $("button:eq(0)").click(function (){
            // $box.hide(); 没有动画效果
            $box.hide(2000); // 有了动画效果  
        })
        $("button:eq(1)").click(function (){
            $box.show();  
        })
        $("button:eq(2)").click(function (){
            $box.toggle("fast");  
        })
        $("button:eq(3)").click(function (){
            $box.slideDown(2000, "linear");  
        })
        $("button:eq(4)").click(function (){
            $box.slideUp(function (){
                alert("动画执行完毕");
            });  
        })
        $("button:eq(5)").click(function (){
            $box.slideToggle();  
        })
        $("button:eq(6)").click(function (){
            $box.fadeOut();  
        })
        $("button:eq(7)").click(function (){
            $box.fadeIn();  
        })
        $("button:eq(8)").click(function (){
            $box.fadeToggle();  
        })


        $("button:eq(9)").click(function (){
            $(".mask").fadeIn(700);
        })

        $(".mask").click(function (){
            $(this).fadeOut(700);
        }).find(".mask-content").click(function (e){
            e.stopPropagation();
        })

    </script>
</body>
</html>